package com.docwei.thansgank.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.docwei.thansgank.R;
import com.docwei.thansgank.callback.ResultBean;

import java.util.List;

/**
 * Created by tobo on 17/7/24.
 */

public class MyOsAdapter extends RecyclerView.Adapter<MyOsAdapter.MyViewHolder> {
    public List<ResultBean.GankBean> mList;
    public Context mContext;

    public MyOsAdapter(List<ResultBean.GankBean> list, Context context) {
        mList = list;
        mContext = context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_os, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        ResultBean.GankBean bean = mList.get(position);
        holder.mTv_author.setText(bean.getWho());
        holder.mTv_date.setText(bean.getPublishedAt().split("T")[0]);
        holder.mTv_title.setText(String.format("%d、%s",position+1,bean.getDesc()));

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder {
        TextView mTv_title;
        TextView mTv_date;
        TextView mTv_author;

        public MyViewHolder(View itemView) {
            super(itemView);
            mTv_title = (TextView) itemView.findViewById(R.id.title);
            mTv_date = (TextView) itemView.findViewById(R.id.date);
            mTv_author = (TextView) itemView.findViewById(R.id.author);
        }
    }
}
